package supermemo.input.ref;
// FileModel.java
// A custom table model to display information on a directory of files.
//
import java.util.List;

import javax.swing.table.AbstractTableModel;

import supermemo.input.Pair;

public class FileModel extends AbstractTableModel {

	String titles[] = new String[] {
			"Source File", "Target File"
	};

	Class types[] = new Class[] { 
			String.class, String.class
	};

	Object data[][] = new Object[0][titles.length];

	public FileModel() 
	{
//		setFileStats(file_list);
	}

	// Implement the methods of the TableModel interface we're interested
	// in.  Only getRowCount(), getColumnCount() and getValueAt() are
	// required.  The other methods tailor the look of the table.
	public int getRowCount() { return data.length; }
	public int getColumnCount() { return titles.length; }
	public String getColumnName(int c) { return titles[c]; }
	public Class getColumnClass(int c) { return types[c]; }
	public Object getValueAt(int r, int c) { return data[r][c]; }

	//  Our own method for setting/changing the current directory
	// being displayed.  This method fills the data set with file info
	// from the given directory.  It also fires an update event so this
	// method could also be called after the table is on display.
	public void setFileStats(List<Pair<String,String>> file_list) 
	{
		int file_num = file_list.size();
		data = new Object[file_num][titles.length];

		for (int i=0; i < file_num; i++) 
		{
			data[i][0] = file_list.get(i).first();
			data[i][1] = file_list.get(i).second();
		}

		// Just in case anyone's listening...
		fireTableDataChanged();
	}
}
